package api

import (
	"fmt"
	"gthoth/internal/app"
	"gthoth/internal/hspcn"

	"github.com/kataras/iris/v12"
)

func RegAPI() {
	API := app.App.Party("/api")
	API.Use(iris.Compression)
	API.Get("/checkcode", func(ctx iris.Context) {
		hspsite := hspcn.NewHspSite()
		b, err := hspsite.GetVirificationCode()
		if err != nil {
			ctx.ResponseWriter().Write([]byte(err.Error()))
			return
		}
		var cookies = hspsite.HspCookie
		fmt.Println(cookies)
		for _, ck := range cookies {
			ctx.SetCookie(ck)
		}
		ctx.ResponseWriter().Write(b)
	})

	API.Post("/login", HspLogin)
	API.Get("/user", HspUserInfo)
	API.Get("/work-list", HspWorkCountList)
	API.Get("/work-detail", HspWorkCountDetailList)
	API.Get("/task-list", HspTaskList)

	// 以下接口需要登录后才能使用
	// API.Use(app.AuthorizeMid)
	// {

	// 	// GET: http://localhost:3008/api/test
	// 	API.Get("/test", func(ctx iris.Context) {
	// 		ctx.WriteString("ok")
	// 	})
	// }
}
